import request from "@/utils/request.js";

/**
 * 用户注册
 * @param username
 * @param password
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userRegisterService = ({name, username, password, phone}) =>
    request.post("/user/register", {
        name,
        username,
        password,
        phone
    })

/**
 * 用户登录
 * @param username
 * @param password
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userLoginService = ({username, password}) =>
    request.post("/user/login", {
        username,
        password
    })

/**
 * 重置密码
 * @param username
 * @param password
 * @param phone
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userResetPassword = (username, password, phone) =>
    request.put("/user", {
        username,
        password,
        phone
    })

/**
 * 用户退出登录
 */
export const userLogoutService = () => {
  request.post('/user/logout',{})
}

/**
 * 查询用户信息
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userGetUserInfoById = (id) =>
    request.get(`/user/${id}`)


/**
 * 添加新地址
 * @param name
 * @param userId
 * @param phone
 * @param address
 * @param status
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userAddNewAddrService = ({ name, userId, phone, address, status }) =>
    request.post("/address", {
        name,
        userId,
        phone,
        address,
        status
    })

/**
 * 根据userId获取地址
 * @param userId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userGetAddrByUserId = (userId) =>
    request.get(`/address/${userId}`)

/**
 * 根据地址id删除地址
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userDeleteAddrById = (id) =>
    request.delete(`/address/${id}`)

/**
 * 更新地址信息
 * @param id
 * @param name
 * @param address
 * @param phone
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userUpdateAddrById = (id, name, address, phone) =>
    request.put(`/address`, {
        id,
        name,
        address,
        phone,
        status: null,
        userId: null
    })

/**
 * 设置默认地址
 * @param id
 * @param userId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userDefaultAddr = (id, userId) =>
    request.put(`/address/default`, {
        id,
        userId
    })












